/**
 */
package org.xtext.context.aware.eventX.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.xtext.context.aware.eventX.ActionType;
import org.xtext.context.aware.eventX.Event;
import org.xtext.context.aware.eventX.EventType;
import org.xtext.context.aware.eventX.EventXPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Event</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.xtext.context.aware.eventX.impl.EventImpl#isHasAction <em>Has Action</em>}</li>
 *   <li>{@link org.xtext.context.aware.eventX.impl.EventImpl#getActionType <em>Action Type</em>}</li>
 *   <li>{@link org.xtext.context.aware.eventX.impl.EventImpl#getEvents <em>Events</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class EventImpl extends ElementImpl implements Event
{
  /**
   * The default value of the '{@link #isHasAction() <em>Has Action</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isHasAction()
   * @generated
   * @ordered
   */
  protected static final boolean HAS_ACTION_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isHasAction() <em>Has Action</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isHasAction()
   * @generated
   * @ordered
   */
  protected boolean hasAction = HAS_ACTION_EDEFAULT;

  /**
   * The cached value of the '{@link #getActionType() <em>Action Type</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getActionType()
   * @generated
   * @ordered
   */
  protected ActionType actionType;

  /**
   * The cached value of the '{@link #getEvents() <em>Events</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getEvents()
   * @generated
   * @ordered
   */
  protected EList<EventType> events;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected EventImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return EventXPackage.Literals.EVENT;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isHasAction()
  {
    return hasAction;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setHasAction(boolean newHasAction)
  {
    boolean oldHasAction = hasAction;
    hasAction = newHasAction;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EventXPackage.EVENT__HAS_ACTION, oldHasAction, hasAction));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public ActionType getActionType()
  {
    return actionType;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetActionType(ActionType newActionType, NotificationChain msgs)
  {
    ActionType oldActionType = actionType;
    actionType = newActionType;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EventXPackage.EVENT__ACTION_TYPE, oldActionType, newActionType);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setActionType(ActionType newActionType)
  {
    if (newActionType != actionType)
    {
      NotificationChain msgs = null;
      if (actionType != null)
        msgs = ((InternalEObject)actionType).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - EventXPackage.EVENT__ACTION_TYPE, null, msgs);
      if (newActionType != null)
        msgs = ((InternalEObject)newActionType).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - EventXPackage.EVENT__ACTION_TYPE, null, msgs);
      msgs = basicSetActionType(newActionType, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EventXPackage.EVENT__ACTION_TYPE, newActionType, newActionType));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<EventType> getEvents()
  {
    if (events == null)
    {
      events = new EObjectContainmentEList<EventType>(EventType.class, this, EventXPackage.EVENT__EVENTS);
    }
    return events;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case EventXPackage.EVENT__ACTION_TYPE:
        return basicSetActionType(null, msgs);
      case EventXPackage.EVENT__EVENTS:
        return ((InternalEList<?>)getEvents()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case EventXPackage.EVENT__HAS_ACTION:
        return isHasAction();
      case EventXPackage.EVENT__ACTION_TYPE:
        return getActionType();
      case EventXPackage.EVENT__EVENTS:
        return getEvents();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case EventXPackage.EVENT__HAS_ACTION:
        setHasAction((Boolean)newValue);
        return;
      case EventXPackage.EVENT__ACTION_TYPE:
        setActionType((ActionType)newValue);
        return;
      case EventXPackage.EVENT__EVENTS:
        getEvents().clear();
        getEvents().addAll((Collection<? extends EventType>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case EventXPackage.EVENT__HAS_ACTION:
        setHasAction(HAS_ACTION_EDEFAULT);
        return;
      case EventXPackage.EVENT__ACTION_TYPE:
        setActionType((ActionType)null);
        return;
      case EventXPackage.EVENT__EVENTS:
        getEvents().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case EventXPackage.EVENT__HAS_ACTION:
        return hasAction != HAS_ACTION_EDEFAULT;
      case EventXPackage.EVENT__ACTION_TYPE:
        return actionType != null;
      case EventXPackage.EVENT__EVENTS:
        return events != null && !events.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (hasAction: ");
    result.append(hasAction);
    result.append(')');
    return result.toString();
  }

} //EventImpl
